package com.zjh.test;

import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@SpringBootTest(classes = MinIOApplication.class)
@RunWith(SpringRunner.class)
public class MinIotest {
    FileInputStream inputStream;
    @Test
    public void uploadtominio() throws IOException, ServerException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        inputStream = new FileInputStream("X://workspace//heimatoutiao//day02//plugins//js/axios.min.js");
//        创建连接minin客户端连接
        MinioClient build = MinioClient.builder()
                .credentials("minio", "minio123")
                .endpoint("http://192.168.200.130:9000")
                .build();
//        2.上传
        PutObjectArgs leadnews = PutObjectArgs.builder()
                .object("plugins/js/axios.min.js")
                .contentType("text/javascript")
                .bucket("leadnews")
                .stream(inputStream, inputStream.available(), -1)
                .build();
        build.putObject(leadnews);
        System.out.println("success");

    }
}
